package com.zb.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zb.Service.PowerService;
import com.zb.entity.Power;
import com.zb.entity.User;

@Scope("prototype")
@Component

@RequestMapping("/filter")
public class PowerFilterController {
	@Autowired
	private PowerService ps;
	@RequestMapping(params = "op=record")
	public String recordFilter(HttpSession session,ModelMap modelmap){
		User suser = (User)session.getAttribute("sys_user");
		Power p = ps.getPowerByRoleId(suser.getRole().getId());
		if(p.getActionrecord()==1){
			return "record";
		}else{
			modelmap.put("msg", "权限不足");
			return "error";
		}
	}
	/**
	 * 孤单是一个小水池里只有一条鱼；
	 * 寂寞是水池里什么也没有。
	 * 孤独是在很多人的地方，身边却没有人陪伴；
	 * 寂寞是在很多人陪伴的时候，也只能沉默。
	 * */
	@RequestMapping(params = "op=power")
	public String powerFilter(HttpSession session,ModelMap modelmap){
		User suser = (User)session.getAttribute("sys_user");
		Power p = ps.getPowerByRoleId(suser.getRole().getId());
		if(p.getRolemanager()==1||suser.getRole().getId()==1){
			return "redirect:power.html?op=show";
		}else{
			modelmap.put("msg", "权限不足");
			return "error";
		}
	}
	@RequestMapping(params = "op=notice")
	public String noticeFilter(HttpSession session,ModelMap modelmap){
		User suser = (User)session.getAttribute("sys_user");
		Power p = ps.getPowerByRoleId(suser.getRole().getId());
		if(p.getShowinfo()==1){
			return "redirect:noticAll.jsp";
		}else{
			modelmap.put("msg", "权限不足");
			return "error";
		}
	}
	@RequestMapping(params = "op=note")
	public String noteFilter(HttpSession session,ModelMap modelmap){
		User suser = (User)session.getAttribute("sys_user");
		Power p = ps.getPowerByRoleId(suser.getRole().getId());
		if(p.getShownote()==1){
			return "redirect:bq.jsp";
		}else{
			modelmap.put("msg", "权限不足");
			return "error";
		}
	}
}
